home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
mac
/
LOGIC Apple II 5.25" Library - ProDOS
/
PRO001.dsk
/
FIN
/
SECURITY.ANAL.bas
< prev
next >
Wrap
BASIC Source File
|
2012-02-16
|
5KB
|
166 lines
1 REM WRITTEN BY ERIC ROSENFELD
2 REM 70 LANCASTER RD.
3 REM ARLINGTON,MA 02174
90 REM IF YOU DO NOT HAVE ENOUGH MEMORY TO RUN THIS PROGRAM CHANGE THE DIM STATEMENT IN 102 (CHANGE FROM 250 TO 100)
100 DIM SEC$(2),PD$(4)
101 DIM A(2),B(2),ALPHA(2,2),BETA(2,2)
102 DIM S(2,250),R(2,250),X(250),Y(250)
103 DIM D(3),STK(2,10)
150 PD$(1) = "DAILY"
151 PD$(2) = "WEEKLY"
152 PD$(3) = "MONTHLY"
153 PD$(4) = "YEARLY"
154 NUM = 2
200 CALL -936
210 VTAB 10: HTAB 10: PRINT "SECURITY ANALYSIS"
215 VTAB 12: PRINT " USING THE CAPITAL ASSET PRICING MODEL"
220 FOR I = 1 TO 3000: NEXT I
300 CALL -936
310 VTAB 12: PRINT "ARE YOU ENTERING DATA FROM"
320 PRINT " 1. KEYBOARD"
330 PRINT " 2. TAPE"
340 INPUT "ENTER APPROPRIATE NUMBER: ";TAPE
350 IF TAPE = 2 GOTO 1000
500 CALL -936
501 PRINT "ENTER THE NAME OF THE MARKET INDEX (UP TO 10 LETTERS):": INPUT SEC$(1)
510 PRINT "ENTER THE NAME OF THE SECURITY (UP TO 10LETTERS):": INPUT SEC$(2)
520 PRINT : PRINT "ENTER THE APPROPRIATE NUMBER:"
530 PRINT "THE DATA IS:"
540 PRINT " 1. DAILY"
550 PRINT " 2. WEEKLY"
560 PRINT " 3. MONTHLY"
570 PRINT " 4. YEARLY"
580 INPUT PERIOD
590 IF PERIOD = 1 THEN T = 1/360
600 IF PERIOD = 2 THEN T = 1/52
610 IF PERIOD = 3 THEN T = 1/12
620 IF PERIOD = 4 THEN T = 1
630 IF PERID <1 OR PERIOD >4 THEN GOTO 520
640 PRINT "ENTER THE NUMBER OF OBSERVATIONS:": INPUT N
650 PRINT : PRINT "ENTER THE CURRENT YIELD ON 1 YEAR TBILLS(IN PERCENT I.E. .09 FOR 9 PERCENT):"
651 INPUT R
654 INIT = 1
655 FOR J = 1 TO 2
660 CALL -936: PRINT "ENTER DATA FOR ";SEC$(J): PRINT
670 FOR I = INIT TO N
680 PRINT "OBSERVATION ";I: INPUT S(J,I)
690 NEXT I: NEXT J
700 CALL -936
710 VTAB 12: INPUT "DO YOU WISH TO SAVE DATA ON TAPE (ENTER Y OR N): ";ANS$
720 IF ANS$ = "N" GOTO 2000
722 FOR J = 1 TO 2
723 STK(J,0) = LEN(SEC$(J))
724 FOR I = 1 TO STK(J,0)
725 STK(J,I) = ASC( MID$ (SEC$(J),I,1))
726 NEXT I: NEXT J
739 CALL -936
740 VTAB 12: PRINT "TURN TAPE ON (RECORD)"
750 PRINT "AND PRESS ANY KEY"
755 D(1) = N:D(2) = PERIOD:D(3) = T
760 GET ANS$
800 STORE STK
820 STORE D
830 STORE S
840 CALL -936
850 VTAB 12: PRINT "TURN TAPE OFF"
870 GOTO 2000
1000 CALL -936
1010 VTAB 12: PRINT "TURN TAPE ON (PLAY)"
1020 PRINT "AND PRESS ANY KEY"
1030 GET ANS$
1040 RECALL STK
1050 RECALL D
1060 RECALL S
1070 N = D(1):PERIOD = D(2):T = D(3)
1080 CALL -936
1090 VTAB 12: PRINT "TURN TAPE OFF"
1100 FOR J = 1 TO 2
1105 FOR I = 1 TO STK(J,0)
1110 SEC$(J) = SEC$(J) + CHR$(STK(J,I))
1120 NEXT I: NEXT J
1200 FOR I = 1 TO 1000: NEXT I
1500 CALL -936
1510 VTAB 12: PRINT : PRINT "ENTER THE CURRENT YIELD ON 1 YEAR TBILLS(IN PERCENT I.E. .09 FOR 9 PERCENT):"
1520 INPUT R
1600 CALL -936
1610 VTAB 12: PRINT "DO YOU WISH TO UPDATE THE DATA (ENTER Y OR N):": GET ANS$
1620 IF ANS$ = "N" GOTO 2000
1630 PRINT : PRINT : PRINT "HOW MANY ADDITIONAL DATA POINTS? "
1640 INPUT ADD
1650 INIT = N +1
1660 N = N +ADD
1700 GOTO 655
2000 FOR J = 1 TO NUM
2010 GOSUB 5000
2020 GOSUB 7000
2030 FOR JJ = 1 TO 3000: NEXT JJ
2040 NEXT J
3000 END
5000 REM CALCULATION ROUTINE
5010 PLOW = S(J,1):PHIGH = S(J,1)
5011 PMEAN = 0:PVAR = 0
5020 FOR I = 1 TO N
5030 IF S(J,I) <PLOW THEN PLOW = S(J,I)
5040 IF S(J,I) >PHIGH THEN PHIGH = S(J,I)
5050 PMEAN = PMEAN +S(J,I)/N
5060 PVAR = PVAR +(S(J,I) ^2)/N
5070 NEXT I
5080 PVAR = PVAR -PMEAN ^2
5200 R(J,2) = (S(J,2)/S(J,1)) -1
5210 RLOW = R(J,2):RHIGH = R(J,2)
5220 RMEAN = 0:RVAR = 0
5222 FOR I = 2 TO N
5225 R(J,I) = (S(J,I)/S(J,I -1)) -1
5230 IF R(J,I) <RLOW THEN RLOW = R(J,I)
5240 IF R(J,I) >RHIGH THEN RHIGH = R(J,I)
5250 RMEAN = RMEAN +R(J,I)/(N -1)
5260 RVAR = RVAR +(R(J,I) ^2)/(N -1)
5270 NEXT I
5280 RVAR = RVAR -RMEAN ^2
5300 RF = ((1 +R) ^T) -1
5400 OBS = N -1
5410 FOR I = 1 TO OBS
5420 X(I) = R(1,I +1) -RF
5430 Y(I) = R(J,I +1) -RF
5440 NEXT I
5500 GOSUB 6000
5510 BETA(1,J) = B(1)
5520 BETA(2,J) = B(2)
5530 ALPHA(1,J) = A(1)
5540 ALPHA(2,J) = A(2)
5999 RETURN
6000 REM LINEAR REGRESSION ROUTINE
6010 XYP = 0:X2P = 0:SST = 0:XMEAN = 0:YMEAN = 0
6020 FOR I = 1 TO OBS
6030 XMEAN = XMEAN +X(I)/OBS:YMEAN = YMEAN +Y(I)/OBS
6040 NEXT I
6050 FOR I = 1 TO OBS
6060 XP = X(I) -XMEAN
6070 YP = Y(I) -YMEAN
6080 XYP = XYP +XP *YP
6090 X2P = X2P +XP ^2
6100 SST = SST +YP ^2
6110 NEXT I
6120 B(1) = XYP/X2P
6130 A(1) = YMEAN -B(1) *XMEAN
6170 S2 = (1/(OBS -2)) *(SST -B(1) *XYP)
6175 IF S2 <0 THEN S2 = 0
6180 B(2) = SQR(S2/X2P)
6190 A(2) = SQR(S2 *((1/OBS) +XMEAN ^2/X2P))
6200 R2 = B(1) ^2 *X2P/SST
6250 RETURN
7000 REM OUTPUT ROUTINE
7001 CALL -936
7002 PRINT "SECURITY ";SEC$(J)
7010 PRINT : PRINT "NUMBER OF OBSERVATIONS ";N
7020 PRINT "PERIODICITY OF DATA ";PD$(PERIOD)
7030 PRINT : PRINT "PRICE DATA RETURN DATA"
7040 PRINT : PRINT "HIGH ";PHIGH;" ";RHIGH
7050 PRINT : PRINT "LOW ";PLOW;" ";RLOW
7060 PRINT : PRINT "MEAN ";PMEAN;" ";RMEAN
7070 PRINT : PRINT "VAR ";PVAR;" ";RVAR
7080 PRINT : PRINT "STD DEV "; SQR(PVAR);" "; SQR(RVAR)"
7090 PRINT : PRINT : PRINT "BETA ";BETA(1,J);" SE ";BETA(2,J)
7100 PRINT "ALPHA ";ALPHA(1,J);" SE ";ALPHA(2,J)
7110 PRINT "R SQUARED ";R2
7200 RETURN